package com.example.pro1.controller.lian;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.example.pro1.controller.lian.oldController.fileControllerOld;
import com.example.pro1.entity.lian.*;
import com.example.pro1.service.lian.*;
import net.sf.json.JSONObject;
import net.sf.json.groovy.GJson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springfox.documentation.spring.web.json.Json;

import java.util.List;

/*客户操作相关接口*/
@Controller
@RequestMapping("/customerManage")
@ResponseBody
@CrossOrigin
public class customerManageController {

    @Autowired
    CustomerService CustomerService;

    @Autowired
    com.example.pro1.service.lian.GorderService GorderService;

    @Autowired
    com.example.pro1.service.lian.CollectionService CollectionService;

    @Autowired
    AddressService AddressService;

    @Autowired
    GoodpreService GoodpreService;

    @Autowired
    com.example.pro1.service.lian.CartService CartService;

    @Autowired
    customerController customerController;

    @Autowired
    goodController goodController;

    @Autowired
    com.example.pro1.service.lian.EvaluationService EvaluationService;

    @Autowired
    com.example.pro1.service.lian.EvaluateimgService EvaluateimgService;



    /*1.微信客户注册接口*/
    @RequestMapping("/registerInWX")
    public Customer registerByWX(
            @RequestParam("cEmail")String cEmail,
            @RequestParam("cSex")String cSex,
            @RequestParam("cWXNumber")String cWXNumber,
            @RequestParam("cWXOpenId")String cWXOpenId,
            @RequestParam("cImgSrc")String cImgSrc
    ){
        Customer Customer = new Customer(
                null,
                "",
                cEmail,
                "",
                cSex,
                cWXNumber,
                cWXOpenId,
                cImgSrc
        );
        if (CustomerService.save(Customer)){
            return Customer;
        }else {
            return null;
        }
    }


    /*2 pc端客户注册接口*/
    @RequestMapping("/registerByPC")
    public Customer registerByPC(
            @RequestParam("cName")String cName,
            @RequestParam("cEmail")String cEmail,
            @RequestParam("cPassword")String cPassword,
            @RequestParam("cSex")String cSex,
            @RequestParam("cWXNumber")String cWXNumber,
            @RequestParam("cImgSrc")String cImgSrc
    ){
        Customer Customer = new Customer(
                null,
                cName,
                cEmail,
                cPassword,
                cSex,
                cWXNumber,
                "",
                cImgSrc
        );
        if (CustomerService.save(Customer)){
            return Customer;
        }else {
            return null;
        }

    }


    /*3 微信端绑定pc端账号*/
    /*前提是已经注册过pc端账号，这个操作相当于合并两个账号*/
    /*删除pc账号，将用户名与密码信息添加到openId账号中，其它信息以openId账号为准*/
    /*将两个账号的信息进行合并*/
    @RequestMapping("/WXBindPC")
    public Customer WXBindPC(
            @RequestParam("openId")String openId,
            @RequestParam("cName")String cName,
            @RequestParam("cPassword")String cPassword
    ){
        /*先检查pc端账号是否存在*/
        Customer PCcustomer = signInByPC(cName, cPassword);
        /*获取微信端的账号信息*/
        Customer WXcustomer = signInByWX(openId);
        if (PCcustomer==null){
            /*没有此pc端账号，绑定失败*/
            return null;
        }else {
            /*获取pc端的cId*/
            String PCCId = PCcustomer.getCid();
            /*获取微信端的cId*/
            String WXCId = WXcustomer.getCid();
            /*1合并收藏信息*/
            /*先获取一个cid的所有对应gid*/
            LambdaQueryWrapper<Collection> CollectionQueryWrapper = new LambdaQueryWrapper<>();
            CollectionQueryWrapper.eq(StringUtils.isNotBlank(WXCId),Collection::getCid,WXCId);
            for (Collection collection : CollectionService.list(CollectionQueryWrapper)) {
                /*查找是否含有符合条件的记录*/
                CollectionQueryWrapper = new LambdaQueryWrapper<>();
                CollectionQueryWrapper
                        .eq(StringUtils.isNotBlank(PCCId),Collection::getCid,PCCId)
                        .eq(StringUtils.isNotBlank(collection.getGid()),Collection::getGid,collection.getGid());
                Collection collectionME = CollectionService.getOne(CollectionQueryWrapper);
                if (collectionME!=null){
                    /*如果确实存在，删除这条记录*/
                    CollectionService.remove(CollectionQueryWrapper);
                }
            }
            /*之后再将pc端的cid改成微信账号的cId*/
            LambdaUpdateWrapper<Collection> CollectionUpdateWrapper = new LambdaUpdateWrapper<>();
            CollectionUpdateWrapper.eq(StringUtils.isNotBlank(PCCId),Collection::getCid,PCCId);
            CollectionUpdateWrapper.set(Collection::getCid,WXCId);
            boolean CollectionUpdate = CollectionService.update(CollectionUpdateWrapper);

            /*2合并订单信息*/
            /*直接将pc端的cid改成微信账号的cId*/
            LambdaUpdateWrapper<Gorder> GorderUpdateWrapper = new LambdaUpdateWrapper<>();
            GorderUpdateWrapper.eq(StringUtils.isNotBlank(PCCId),Gorder::getCid,PCCId);
            GorderUpdateWrapper.set(Gorder::getCid,WXCId);
            boolean GorderUpdate = GorderService.update(GorderUpdateWrapper);

            /*3合并购物车信息*/
            /*先获取一个cid的所有对应gid*/
            LambdaQueryWrapper<Cart> CartQueryWrapper = new LambdaQueryWrapper<>();
            CartQueryWrapper.eq(StringUtils.isNotBlank(WXCId), Cart::getCid,WXCId);
            for (Cart cart : CartService.list(CartQueryWrapper)) {
                /*查找是否含有符合条件的记录*/
                CartQueryWrapper = new LambdaQueryWrapper<>();
                CartQueryWrapper
                        .eq(StringUtils.isNotBlank(PCCId),Cart::getCid,PCCId)
                        .eq(StringUtils.isNotBlank(cart.getGid()),Cart::getGid,cart.getGid());
                Cart CartME = CartService.getOne(CartQueryWrapper);
                if (CartME!=null){
                    /*如果确实存在，删除这条记录*/
                    CartService.remove(CartQueryWrapper);
                }
            }
            /*之后再将pc端的cid改成微信账号的cId*/
            LambdaUpdateWrapper<Cart> CartUpdateWrapper = new LambdaUpdateWrapper<>();
            CartUpdateWrapper.eq(StringUtils.isNotBlank(PCCId),Cart::getCid,PCCId);
            CartUpdateWrapper.set(Cart::getCid,WXCId);
            boolean CartUpdate = CartService.update(CartUpdateWrapper);


            /*4合并客户地址信息*/
            /*直接将pc端的cid改成微信账号的cId*/
            LambdaUpdateWrapper<Address> AddressUpdateWrapper = new LambdaUpdateWrapper<>();
            AddressUpdateWrapper.eq(StringUtils.isNotBlank(PCCId),Address::getCid,PCCId);
            AddressUpdateWrapper.set(Address::getCid,WXCId);
            boolean AddressUpdate = AddressService.update(AddressUpdateWrapper);

            /*5合并优惠卷信息*/
            /*直接将pc端的cid改成微信账号的cId*/
            LambdaUpdateWrapper<Goodpre> GoodpreUpdateWrapper = new LambdaUpdateWrapper<>();
            GoodpreUpdateWrapper.eq(StringUtils.isNotBlank(PCCId),Goodpre::getCid,PCCId);
            GoodpreUpdateWrapper.set(Goodpre::getCid,WXCId);
            boolean GoodpreUpdate = GoodpreService.update(GoodpreUpdateWrapper);

            /*先删除pc端的账号*/
            if (deleteAccountByPCAccount(cName,cPassword)){
                /*再更新微信的账号*/
                LambdaUpdateWrapper<Customer> CustomerUpdateWrapper = new LambdaUpdateWrapper<>();
                CustomerUpdateWrapper
                        .eq(StringUtils.isNotBlank(openId),Customer::getCwxopenid,openId);
                CustomerUpdateWrapper
                        .set(Customer::getCname,cName)
                        .set(Customer::getCpassword,cPassword);
                if (CustomerService.update(CustomerUpdateWrapper)){
                    /*修改成功，返回客户信息*/
                    return signInByWX(openId);
                }else {
                    return null;
                }
            }else {
                /*删除失败，绑定失败*/
                return null;
            }
        }

    }


    /*3.1根据openId查看是否已经绑定pc端账号*/
    @RequestMapping("/havePCAccount")
    public Boolean havePCAccount(@RequestParam("openId")String openId){
        Customer customer = signInByWX(openId);
        if (customer!=null&&StringUtils.isNotBlank(customer.getCname())&&StringUtils.isNotBlank(customer.getCpassword())){
            return true;
        }else {
            return false;
        }
    }


    /*3.2检查pc端用户名是否存在*/
    @RequestMapping("/isPCExist")
    public Boolean isCNameExist(@RequestParam("cName")String cName){
        LambdaQueryWrapper<Customer> CustomerQueryWrapper = new LambdaQueryWrapper<>();
        CustomerQueryWrapper.eq(StringUtils.isNotBlank(cName),Customer::getCname,cName);
        Customer customer = CustomerService.getOne(CustomerQueryWrapper);
        if (customer!=null) {
            return true;
        }else {
            return false;
        }
    }


    /*3.3根据openId注销一个账号*/
    /*外键太多，这个可能不行*/
    public Boolean deleteAccountByPCAccount(String cName,String cPassword){
        LambdaQueryWrapper<Customer> CustomerQueryWrapper = new LambdaQueryWrapper<>();
        CustomerQueryWrapper
                .eq(StringUtils.isNotBlank(cName),Customer::getCname,cName)
                .eq(StringUtils.isNotBlank(cPassword),Customer::getCpassword,cPassword);
        return CustomerService.remove(CustomerQueryWrapper);
    }



    /*4.微信端客户登录接口*/
    /*根据openId获取对应客户相关信息*/
    @RequestMapping("/signInByWX")
    public Customer signInByWX(@RequestParam("openId")String openId){
        LambdaQueryWrapper<Customer> CustomerQueryWrapper = new LambdaQueryWrapper<>();
        CustomerQueryWrapper.eq(StringUtils.isNotBlank(openId),Customer::getCwxopenid,openId);
        return CustomerService.getOne(CustomerQueryWrapper);
    }


    /*5.pc端客户登录接口*/
    /*根据用户名与密码获取客户信息*/
    @RequestMapping("/signInByPC")
    public Customer signInByPC(
            @RequestParam("cName")String cName,
            @RequestParam("cPassword")String cPassword
    ){
        LambdaQueryWrapper<Customer> CustomerQueryWrapper = new LambdaQueryWrapper<>();
        CustomerQueryWrapper
                .eq(StringUtils.isNotBlank(cName),Customer::getCname,cName)
                .eq(StringUtils.isNotBlank(cPassword),Customer::getCpassword,cPassword);
        return CustomerService.getOne(CustomerQueryWrapper);
    }

    /*还没有添加*/

    /*6.根据cId客户端添加收藏接口*/
    @RequestMapping("/addCollectionPC")
    public Boolean addCollectionPC(
            @RequestParam("cId")String cId,
            @RequestParam("gId")String gId){
        Collection Collection = new Collection(cId,gId);
        return CollectionService.save(Collection);
    }

    /*6.1 根据openId客户端添加收藏接口*/
    @RequestMapping("/addCollectionWX")
    public Boolean addCollectionWX(
            @RequestParam("openId")String openId,
            @RequestParam("gId")String gId
    ){
        /*根据openId获取cId*/
        String cId = customerController.getCIdByOpenId(openId);
        return addCollectionPC(cId,gId);
    }



    /*7.根据cId客户端取消收藏接口*/
    @RequestMapping("/removeCollectionPC")
    public Boolean removeCollectionPC(@RequestParam("cId")String cId,
                                         @RequestParam("gId")String gId){
        LambdaQueryWrapper<Collection> CollectionQueryWrapper = new LambdaQueryWrapper<>();
        CollectionQueryWrapper
                .eq(StringUtils.isNotBlank(cId),Collection::getCid,cId)
                .eq(StringUtils.isNotBlank(gId),Collection::getGid,gId);
        return CollectionService.remove(CollectionQueryWrapper);
    }


    /*7.1.根据openId客户端取消收藏接口*/
    @RequestMapping("/removeCollectionWX")
    public Boolean removeCollectionWX(@RequestParam("openId")String openId,
                                      @RequestParam("gId")String gId){
        String cId = customerController.getCIdByOpenId(openId);
        return removeCollectionPC(cId, gId);
    }

    /*7.3 查看当前客户是否收藏商品PC*/
    @RequestMapping("/haveGoodInCollectionPC")
    public Boolean haveGoodInCollectionPC(
            @RequestParam("cId")String cId,
            @RequestParam("gId")String gId
    ){
        LambdaQueryWrapper<Collection> CollectionQueryWrapper = new LambdaQueryWrapper<>();
        CollectionQueryWrapper
                .eq(StringUtils.isNotBlank(cId),Collection::getCid,cId)
                .eq(StringUtils.isNotBlank(gId),Collection::getGid,gId);
        Collection one = CollectionService.getOne(CollectionQueryWrapper);
        if (one!=null){
            return true;
        }else{
            return false;
        }
    }


    /*7.4查看当前客户是否收藏商品WX*/
    @RequestMapping("/haveGoodInCollectionWX")
    public Boolean haveGoodInCollectionWX(
            @RequestParam("openId")String openId,
            @RequestParam("gId")String gId
    ){
        String cId = customerController.getCIdByOpenId(openId);
        return haveGoodInCollectionPC(cId, gId);
    }


    /*8.客户根据cId和gId添加进入购物车接口*/
    @RequestMapping("/addCartInfoPC")
    public Boolean addCartInfoPC(
            @RequestParam("cId")String cId,
            @RequestParam("gId")String gId,
            @RequestParam("buyNum")Integer buyNum
    ){
        Cart Cart = new Cart(cId,gId,buyNum);
        return CartService.save(Cart);
    }

    /*8.1客户根据openId与gId添加进入购物车接口*/
    @RequestMapping("/addCartInfoWX")
    public Boolean addCartInfoWX(
            @RequestParam("openId")String openId,
            @RequestParam("gId")String gId,
            @RequestParam("buyNum")Integer buyNum
    ){
        String cId = customerController.getCIdByOpenId(openId);
        return addCartInfoPC(cId, gId, buyNum);
    }

    /*9.客户根据cId和gId删除购物车接口*/
    @RequestMapping("/removeCartPC")
    public Boolean removeCartPC(
            @RequestParam("cId")String cId,
            @RequestParam("gId")String gId
    ){
        LambdaQueryWrapper<Cart> CartQueryWrapper = new LambdaQueryWrapper<>();
        CartQueryWrapper.eq(StringUtils.isNotBlank(cId),Cart::getCid,cId)
                .eq(StringUtils.isNotBlank(gId),Cart::getGid,gId);
        return CartService.remove(CartQueryWrapper);
    }

    /*9.1客户根据openId与gId删除购物车接口*/
    @RequestMapping("/removeCartWX")
    public Boolean removeCartWX(
            @RequestParam("openId")String openId,
            @RequestParam("gId")String gId
    ){
        String cId = customerController.getCIdByOpenId(openId);
        return removeCartPC(cId, gId);
    }

    /*9.11根据cId和gId查看当前购物车中是否含有此商品*/
    @RequestMapping("/haveGoodInCart")
    public Boolean haveGoodInCartPC(
            @RequestParam("cId")String cId,
            @RequestParam("gId")String gId
    ){
        LambdaQueryWrapper<Cart> CartQueryWrapper = new LambdaQueryWrapper<>();
        CartQueryWrapper
                .eq(StringUtils.isNotBlank(cId),Cart::getCid,cId)
                .eq(StringUtils.isNotBlank(gId),Cart::getGid,gId);
        Cart one = CartService.getOne(CartQueryWrapper);
        if (one!=null){
            return true;
        }else {
            return false;
        }
    }

    /*9.12根据openId和gId查看当前购物车中是否含有此商品*/
    @RequestMapping("/haveGoodInCartWX")
    public Boolean haveGoodInCartWX(
        @RequestParam("openId")String openId,
        @RequestParam("gId")String gId
    ){
        String cId = customerController.getCIdByOpenId(openId);
        return haveGoodInCartPC(cId, gId);
    }




    /*10.客户根据gId与cId修改购物车信息接口(需要数量num)*/
    @RequestMapping("/updateCartInfoPC")
    public Boolean updateCartInfoPC(
            @RequestParam("cId")String cId,
            @RequestParam("gId")String gId,
            @RequestParam("buyNum")Integer buyNum
    ){
        LambdaUpdateWrapper<Cart> CartUpdateWrapper = new LambdaUpdateWrapper<>();
        CartUpdateWrapper
                .eq(StringUtils.isNotBlank(cId),Cart::getCid,cId)
                .eq(StringUtils.isNotBlank(gId),Cart::getGid,gId)
                .set(Cart::getBuynum,buyNum);
        return CartService.update(CartUpdateWrapper);
    }


    /*11.客户根据gId与openId修改购物车信息接口(需要数量num)*/
    @RequestMapping("/updateCartInfoWX")
    public Boolean updateCartInfoWX(
            @RequestParam("openId")String openId,
            @RequestParam("gId")String gId,
            @RequestParam("buyNum")Integer buyNum
    ){
        String cId = customerController.getCIdByOpenId(openId);
        return updateCartInfoPC(cId,gId,buyNum);
    }


    /*12.客户根据cId添加地址接口*/
    @RequestMapping("/addAddressPC")
    public Boolean addAddressPC(
            @RequestParam("cId") String cId,
            @RequestParam("name")String name,
            @RequestParam("phone")String phone,
            @RequestParam("location")String location,
            @RequestParam("addressDetail")String addressDetail,
            @RequestParam("isDefault")String isDefault
    ){
        Address Address = new Address(
                null,
                cId,
                name,
                phone,
                location,
                addressDetail,
                isDefault
        );
        return AddressService.save(Address);
    }


    /*13.客户根据openId添加地址接口*/
    @RequestMapping("/addAddressWX")
    public Boolean addAddressWX(
            @RequestParam("openId") String openId,
            @RequestParam("name")String name,
            @RequestParam("phone")String phone,
            @RequestParam("location")String location,
            @RequestParam("addressDetail")String addressDetail,
            @RequestParam("isDefault")String isDefault
    ){
        String cId = customerController.getCIdByOpenId(openId);
        return addAddressPC(
                cId,
                name,
                phone,
                location,
                addressDetail,
                isDefault
        );
    }

    /*14.客户根据cId查询是否含有默认地址*/
    @RequestMapping("/haveDefaultAddressPC")
    public Boolean haveDefaultAddressPC(
            @RequestParam("cId")String cId
    ){
        LambdaQueryWrapper<Address> AddressQueryWrapper = new LambdaQueryWrapper<>();
        AddressQueryWrapper
                .eq(StringUtils.isNotBlank(cId),Address::getCid,cId)
                .eq(true,Address::getIsdefault,"true");
        Address one = AddressService.getOne(AddressQueryWrapper);
        if (one==null){
            return false;
        }else {
            return true;
        }
    }

    /*15.客户根据openId查询是否含有默认地址接口*/
    @RequestMapping("/haveDefaultAddressWX")
    public Boolean haveDefaultAddressWX(
            @RequestParam("openId")String openId
    ){
        String cId = customerController.getCIdByOpenId(openId);
        return haveDefaultAddressPC(cId);
    }


    /*16.客户根据地址id修改地址信息接口*/
    @RequestMapping("/updateAddressByAddressId")
    public Boolean updateAddressByAddressId(
            @RequestParam("addressid")String addressid,
            @RequestParam("name")String name,
            @RequestParam("phone")String phone,
            @RequestParam("location")String location,
            @RequestParam("addressDetail")String addressDetail,
            @RequestParam("isDefault")String isDefault
    ){
        LambdaUpdateWrapper<Address> AddressUpdateWrapper = new LambdaUpdateWrapper<>();
        AddressUpdateWrapper
                .eq(StringUtils.isNotBlank(addressid),Address::getAddressid,addressid)
                .set(Address::getName,name)
                .set(Address::getPhone,phone)
                .set(Address::getLocation,location)
                .set(Address::getAddressdetail,addressDetail)
                .set(Address::getIsdefault,isDefault);
        return AddressService.update(AddressUpdateWrapper);
    }


    /*17客户根据地址id删除地址信息.*/
    @RequestMapping("/removeAddressByAddressId")
    public Boolean removeAddressByAddressId(
            @RequestParam("addressid")String addressid
    ){
        LambdaQueryWrapper<Address> AddressQueryWrapper = new LambdaQueryWrapper<>();
        AddressQueryWrapper.eq(StringUtils.isNotBlank(addressid),Address::getAddressid,addressid);
        return AddressService.remove(AddressQueryWrapper);
    }

    /*18获取客户默认地址信息PC*/
    @RequestMapping("/getDefaultAddressPC")
    public Address getDefaultAddressPC(
            @RequestParam("cId")String cId
    ){
        LambdaQueryWrapper<Address> AddressQueryWrapper = new LambdaQueryWrapper<>();
        AddressQueryWrapper
                .eq(StringUtils.isNotBlank(cId),Address::getCid,cId)
                .eq(Address::getIsdefault,"true");
        return AddressService.getOne(AddressQueryWrapper);
    }

    /*18.1获取客户默认地址信息WX*/
    @RequestMapping("/getDefaultAddressWX")
    public Address getDefaultAddressWX(
            @RequestParam("openId")String openId
    ){
        String cId = customerController.getCIdByOpenId(openId);
        return getDefaultAddressPC(cId);
    }


    /*19将客户所有的地址全部设置为非默认PC*/
    @RequestMapping("/setAllAddressDefaultPC")
    public boolean setAllAddressDefaultPC(@RequestParam("cId")String cId){
        LambdaUpdateWrapper<Address> AddressUpdateWrapper = new LambdaUpdateWrapper<>();
        AddressUpdateWrapper
                .eq(StringUtils.isNotBlank(cId),Address::getCid,cId)
                .set(Address::getIsdefault,"false");
        return AddressService.update(AddressUpdateWrapper);
    }

    /*19.1将客户所有的地址全部设置为非默认WX*/
    @RequestMapping("/setAllAddressDefaultWX")
    public boolean setAllAddressDefaultWX(@RequestParam("openId")String openId){
        String cId = customerController.getCIdByOpenId(openId);
        return setAllAddressDefaultPC(cId);
    }

    /*20.将某个地址信息设置为默认*/
    @RequestMapping("/setAddressDefaultByAddressId")
    public boolean setAddressDefaultByAddressId(@RequestParam("addressid")String addressid){
        LambdaUpdateWrapper<Address> AddressUpdateWrapper = new LambdaUpdateWrapper<>();
        AddressUpdateWrapper
                .eq(StringUtils.isNotBlank(addressid),Address::getAddressid,addressid)
                .set(Address::getIsdefault,"true");
        return AddressService.update(AddressUpdateWrapper);
    }

    /*21.将客户除了某个地址的地址外全部改成非默认地址PC*/
    @RequestMapping("/setAddressDefaultExceptOnePC")
    public boolean setAddressDefaultExceptOnePC(
            @RequestParam("addressid")String addressid,
            @RequestParam("cId")String cId
    ){
        LambdaUpdateWrapper<Address> AddressUpdateWrapper = new LambdaUpdateWrapper<>();
        AddressUpdateWrapper
                .eq(StringUtils.isNotBlank(cId),Address::getCid,cId)
                .ne(StringUtils.isNotBlank(addressid),Address::getAddressid,addressid)
                .set(Address::getIsdefault,"true");
        return AddressService.update(AddressUpdateWrapper);
    }

    /*22.将客户除了某个地址的地址外全部改成非默认地址WX*/
    @RequestMapping("/setAddressDefaultExceptOneWX")
    public boolean setAddressDefaultExceptOneWX(
            @RequestParam("addressid")String addressid,
            @RequestParam("openId")String openId
    ){
        String cId = customerController.getCIdByOpenId(openId);
        return setAddressDefaultExceptOnePC(addressid, cId);
    }


    /*新接口，没有加文档*/

    /*23.根据cId获取客户新发放的优惠卷信息*/
    @RequestMapping("/getNotInformedGoodprePC")
    public List<Goodpre> getNotInformedGoodprePC(
        @RequestParam("cId") String cId
    ){
        LambdaQueryWrapper<Goodpre> GoodpreQueryWrapper = new LambdaQueryWrapper<>();
        GoodpreQueryWrapper
                .eq(StringUtils.isNotBlank(cId),Goodpre::getCid,cId)
                .eq(true,Goodpre::getIsinformed,0);
        return GoodpreService.list(GoodpreQueryWrapper);
    }


    /*24.根据opneId获取客户新发放的优惠卷信息*/
    @RequestMapping("/getNotInformedGoodpreWX")
    public List<Goodpre> getNotInformedGoodpreWX(
            @RequestParam("openId")String openId
    ){
        String cId = customerController.getCIdByOpenId(openId);
        return getNotInformedGoodprePC(cId);
    }


    /*25.根据cId将客户所有的优惠卷状态设为已通知*/
    @RequestMapping("/allInformedPC")
    public Boolean allInformedPC(
        @RequestParam("cId")String cId
    ){
        LambdaUpdateWrapper<Goodpre> GoodpreUpdateWrapper = new LambdaUpdateWrapper<>();
        GoodpreUpdateWrapper
                .eq(StringUtils.isNotBlank(cId),Goodpre::getCid,cId)
                .set(Goodpre::getIsinformed,1);
        return GoodpreService.update(GoodpreUpdateWrapper);
    }

    /*26.根据openId将客户所有的优惠卷状态设为已通知*/
    @RequestMapping("/allInformedWX")
    public Boolean allInformedWX(
        @RequestParam("openId")String openId
    ){
        String cId = customerController.getCIdByOpenId(openId);
        return allInformedPC(cId);
    }

    /*27.判断客户当前是否还有未查看的优惠卷信息PC*/
    @RequestMapping("/haveNotInformedGoodprePC")
    public Boolean haveNotInformedGoodprePC(
            @RequestParam("cId") String cId
    ){
        List<Goodpre> notInformedGoodprePC = getNotInformedGoodprePC(cId);
        if (notInformedGoodprePC.size()!=0){
            return true;
        }else {
            return false;
        }
    }


    /*28.判断当前客户是否还有未查看的优惠卷信息WX*/
    @RequestMapping("/haveNotInformedGoodpreWX")
    public Boolean haveNotInformedGoodpreWX(
        @RequestParam("openId")String openId
    ){
        String cId = customerController.getCIdByOpenId(openId);
        return haveNotInformedGoodprePC(cId);
    }


    /*29.对于当前购买的商品查看是否有可用的优惠卷，如果有返回优惠卷信息列表，如果没有，返回空列表*/
    @RequestMapping("/goodPreCanUsePC")
    public List<Goodpre> goodPreCanUsePC(
            @RequestParam("cId")String cId,
            @RequestParam("gId")String gId
    ){
        LambdaQueryWrapper<Goodpre> GoodpreQueryWrapper = new LambdaQueryWrapper<>();
        GoodpreQueryWrapper
                .eq(StringUtils.isNotBlank(gId),Goodpre::getGid,gId)
                .eq(StringUtils.isNotBlank(cId),Goodpre::getCid,cId)
                .eq(true,Goodpre::getIsused,0);
        return GoodpreService.list(GoodpreQueryWrapper);
    }

    /*29.1 29的WX版本*/
    @RequestMapping("/goodPreCanUseWX")
    public List<Goodpre> goodPreCanUseWX(
        @RequestParam("openId")String openId,
        @RequestParam("gId")String gId
    ){
        String cId = customerController.getCIdByOpenId(openId);
        return goodPreCanUsePC(cId, gId);
    }


    /*30.确认使用某优惠卷*/
    @RequestMapping("/useGoodpreById")
    public Boolean useGoodpreById(
            @RequestParam("preId")String preId
    ){
        LambdaUpdateWrapper<Goodpre> GoodpreUpdateWrapper = new LambdaUpdateWrapper<>();
        GoodpreUpdateWrapper
                .eq(StringUtils.isNotBlank(preId),Goodpre::getPreid,preId)
                .set(true,Goodpre::getIsused,1)
                .set(true,Goodpre::getIsinformed,1);
        return GoodpreService.update(GoodpreUpdateWrapper);
    }

    /*还没有加入文档*/

    /*31.客户针对某订单进行评价PC*/
    @RequestMapping("/evaluateOrder")
    public Boolean evaluateOrder(
            @RequestParam("oId")String oId,
            @RequestParam("evaluation")String evaluation,
            @RequestParam("imgList") List<String> imgList
    ){
        Evaluation Evaluation = new Evaluation(
                null,
                oId,
                evaluation
        );
        boolean save1 = EvaluationService.save(Evaluation);

        int k=imgList.size();
        int i=0;
        for (String s : imgList) {//泽宇爱心xiu'gai
            i++;
            StringBuffer d=new StringBuffer(s);
            if(i==1)
                d.deleteCharAt(0);
            else
            {
                if(i==k)
                    d.deleteCharAt(d.length()-1);
            }
            d.deleteCharAt(0);
            d.deleteCharAt(d.length()-1);
            s=new String(d);

            Evaluateimg Evaluateimg = new Evaluateimg(Evaluation.getEvaluationid(),s);
            System.out.println(s);
            EvaluateimgService.save(Evaluateimg);
        }
        return save1;
    }



    /*还没加入*/
    /*32根据客户id进行修改操作*/
    @RequestMapping("/updateCustomerInfo")
    public Boolean updateCustomerInfo(
            @RequestParam("cId")String cId,
            @RequestParam("cName")String cName,
            @RequestParam("cEmail")String cEmail,
            @RequestParam("cSex")String cSex,
            @RequestParam("cPhone")String cPhone,
            @RequestParam("cImg")String cImg
    ){
        LambdaUpdateWrapper<Customer> customerUpdateWrapper = new LambdaUpdateWrapper<>();
        customerUpdateWrapper
                .eq(StringUtils.isNotBlank(cId),Customer::getCid,cId)
                .set(Customer::getCname,cName)
                .set(Customer::getCemail,cEmail)
                .set(Customer::getCsex,cSex)
                .set(Customer::getCimgsrc,cImg);
        return CustomerService.update(customerUpdateWrapper);
    }

    @Autowired
    fileControllerOld fileControllerOld;
    /*还没加入*/
    /*32根据客户id进行修改操作*/
    @PostMapping(value = "/updateCustomerInfoWithImg")
    public Boolean updateCustomerInfoWithImg(
            @RequestParam("cId")String cId,
            @RequestParam("cName")String cName,
            @RequestParam("cEmail")String cEmail,
            @RequestParam("cSex")String cSex,
            @RequestPart("Imagefile") MultipartFile file
    ){
        String cImg = fileControllerOld.saveImage(file);

        LambdaUpdateWrapper<Customer> customerUpdateWrapper = new LambdaUpdateWrapper<>();
        customerUpdateWrapper
                .eq(StringUtils.isNotBlank(cId),Customer::getCid,cId)
                .set(Customer::getCname,cName)
                .set(Customer::getCemail,cEmail)
                .set(Customer::getCsex,cSex)
                .set(Customer::getCimgsrc,cImg);
        return CustomerService.update(customerUpdateWrapper);
    }

    /*根据cId修改用户名与密码*/
    @RequestMapping("/updateCustomer")
    public Boolean updateCustomer(
        @RequestParam("cId")String cId,
        @RequestParam("cPassword")String password,
        @RequestParam("cName")String userName
    ){
        LambdaUpdateWrapper<Customer> CustomerUpdateWrapper = new LambdaUpdateWrapper<>();
        CustomerUpdateWrapper
                .eq(StringUtils.isNotBlank(cId),Customer::getCid,cId)
                .set(Customer::getCname,userName)
                .set(Customer::getCpassword,password);
        /*更新*/
        return CustomerService.update(CustomerUpdateWrapper);
    }

}
